<template>
    <a-card :bordered="false">

        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
            <a-form layout="inline" @keyup.enter.native="searchQuery">
                <a-row :gutter="24">
                    <template>
                        <a-col :md="6" :sm="8">
                            <a-form-item label="设备名称">
                                <a-input placeholder="请输入设备名称查询" v-model="queryParam.name"></a-input>
                            </a-form-item>
                        </a-col>
                        <a-col :md="6" :sm="8">
                            <a-form-item label="设备型号:">
                                <a-select placeholder="请选择设备型号" v-model="queryParam.modelId">
                                    <a-select-option v-for="item in modelList" :key="item.modelId"
                                                     :value="item.modelId">
                                        {{item.name}}
                                    </a-select-option>
                                </a-select>
                            </a-form-item>
                        </a-col>
                        <a-col :md="6" :sm="8">
                            <a-form-item label="是否在线:">
                                <a-select placeholder="请选择是否在线" showSearch showArrow optionFilterProp="children"
                                          :getPopupContainer="(node) => node.parentNode"
                                          :defaultActiveFirstOption="false" v-model="queryParam.online">
                                    <a-select-option value="1">是</a-select-option>
                                    <a-select-option value="0">否</a-select-option>
                                </a-select>
                            </a-form-item>
                        </a-col>
                    </template>

                    <a-col :md="6" :sm="8">
						<span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
							<a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
							<a-button type="primary" @click="resetParam" icon="reload" style="margin-left: 8px">重置
							</a-button>
						</span>
                    </a-col>

                </a-row>
            </a-form>
        </div>

        <!-- table区域-begin -->
        <div>
            <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
                <i class="anticon anticon-info-circle ant-alert-icon"></i>已选择&nbsp;<a
                    style="font-weight: 600">{{ selectedRowKeys.length }}</a>项&nbsp;&nbsp;
                <a style="margin-left: 24px" @click="onClearSelected">清空</a>
            </div>

            <a-table ref="table" bordered size="middle" rowKey="devId" :columns="columns" :dataSource="dataSource"
                     :pagination="ipagination" :loading="loading"
                     :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
                     @change="handleTableChange">
				
				<span slot="action2" slot-scope="text, record">
					<a @click="cameraList(record)">管理</a>
				</span>
                <span slot="action" slot-scope="text, record">
					<a-divider type="vertical"/>
					<a-dropdown>
						<a class="ant-dropdown-link">
							更多
							<a-icon type="down"/>
						</a>
						<a-menu slot="overlay">
							<a-menu-item>
								<a href="javascript:;" @click="devDetail(record)">详情</a>
							</a-menu-item>
						</a-menu>
					</a-dropdown>
				</span>
            </a-table>
        </div>
        <!-- table区域-end -->
    </a-card>
</template>

<script>
    import {
        JeecgListMixin
    } from '@/mixins/JeecgListMixin'
    import {
        getAction,
        postAction
    } from '@/api/manage'

    export default {
        name: "PlatformDevList",
        mixins: [JeecgListMixin],
        data() {
            return {
                description: '这是设备管理页面',
                queryParam: {
                    name: undefined,
                    modelId: undefined,
                    online: undefined
                },
                modelList: [],
                columns: [
                    {
                        title: '平台标识',
                        align: "center",
                        dataIndex: 'regionId',
                        width: 60
                    },
                    {
                        title: '设备名称',
                        align: "center",
                        dataIndex: 'name',
                        width: 60
                    },
                    {
                        title: '设备编号',
                        align: "center",
                        dataIndex: 'devCode',
                        width: 100
                    },
                    {
                        title: '型号',
                        align: "center",
                        dataIndex: 'modelName',
                        width: 50
                    },
                    {
                        title: '设备类型',
                        align: "center",
                        width: 60,
                        dataIndex: 'typeDesc',
                    },
                    {
                        title: '编码通道数',
                        align: "center",
                        width: 60,
                        dataIndex: 'encodeChannelNum'
                    },
                    {
                        title: '设备描述',
                        align: "center",
                        width: 60,
                        dataIndex: 'devDesc'
                    },
                    {
                        title: '设备地点',
                        align: "center",
                        width: 60,
                        dataIndex: 'location'
                    },
                    {
                        title: 'IP地址',
                        align: "center",
                        width: 60,
                        dataIndex: 'devAddr',
                    },
                    {
                        title: '是否在线',
                        align: "center",
                        width: 60,
                        dataIndex: 'online',
                        customRender: function (text) {
                            if (text == 1) {
                                return "是"
                            } else if (text == 0) {
                                return "否"
                            }
                        }
                    },
                    {
                        title: '启用状态',
                        align: "center",
                        width: 60,
                        dataIndex: 'used',
                        customRender: function (text) {
                            if (text == 1) {
                                return "启用"
                            } else if (text == 0) {
                                return "禁用"
                            }
                        }
                    },
                    {
                        title: '管理摄像机',
                        dataIndex: 'action2',
                        scopedSlots: {
                            customRender: 'action2'
                        },
                        align: "center",
                        width: 80
                    },
                    // {
                    // 	title: '操作',
                    // 	dataIndex: 'action',
                    // 	scopedSlots: {
                    // 		customRender: 'action'
                    // 	},
                    // 	align: "center",
                    // 	width: 80
                    // }
                ],
                url: {
                    list: "/platform/dev-page"
                },
            }
        },
        created() {
            //初始化数据，获取类型
            getAction("/dev/model/list").then((res) => {
                if (res.code == "00000") {
                    this.modelList = res.data
                } else {
                    this.$message.warning("获取型号错误");
                    // this.close(this.modelList);
                }
            })

        },
        methods: {
            addDev: function () {
                this.$refs.modalForm.show();
                this.$refs.modalForm.disableSubmit = false;
                this.$refs.modalForm.modelList = this.modelList;
            },
            modalFormOk() {
                // 新增/修改 成功时，重载列表
                this.loadData();
            },
            editDev: function (record) {
                this.$refs.deveditmodal.show(record);
                this.$refs.deveditmodal.disableSubmit = false;
                this.$refs.deveditmodal.modelList = this.modelList;
            },
            editModalOk() {
                // 修改 成功时，重载列表
                this.loadData();
            },
            devDetail: function (record) {
                this.$refs.deveditmodal.show(record);
                this.$refs.deveditmodal.title = "详情";
                this.$refs.deveditmodal.disableSubmit = true;
            },
            handleMenuClick(e) {
                if (e.key == 1) {
                    this.batchDel();
                }
            },
            resetParam() {
                this.queryParam = {}
                this.queryParam.userType = undefined
                this.loadData(1)
            },
            //路由跳转，打开新的tab
            cameraList(record) {
                console.log(JSON.stringify(record.devId))
                //关闭tab
                // this.$parent.closeRouteViewTab('dev/camera')

                //跳转新tab
                this.$router.push({
                    name: '/parent/camera',
                    params: {
                        devId: record.devId
                    }
                })
                // this.routerRefresh();//调用app.vue里面的routerRefresh()方法，完成摧毁和重建过程
            }
        }
    }
</script>
<style scoped>
    @import '~@assets/less/common.less'
</style>
